import React, { Component } from "react";
import store from "../../store";
export default class ReduxUsePage extends Component {
      addData = () => {
            store.dispatch({ type: "ADD", payload: 100 });
      };

      asyAdd = () => {
            store.dispatch((dispatch, getState) => {
                  setTimeout(() => { 
                        dispatch({ type: "ADD", payload: 1 });
                  }, 1000);
            });
      };

      componentDidMount() {
            store.subscribe(() => {
                  this.forceUpdate();
            });
      }

      render() {
            return (
                  <div>
                        <h1>ReduxUsePage</h1>
                        <p>{store.getState().count}</p>
                        <button onClick={this.addData}>add</button>
                        <button onClick={this.asyAdd}>asyAdd</button>
                  </div>
            );
      }
}
